import 'package:flutter/material.dart' ;
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mfkb/pages/modules/login/InputField.dart';
import 'package:mfkb/service/UserService.dart';
import 'package:toast/toast.dart';

class Opinion extends StatefulWidget {
  @override
  _OpinionState createState() => _OpinionState();
}

class _OpinionState extends State<Opinion> {

  String content ;
  String uploadContent ;

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.dark ,
      child: Scaffold(
        body: Container(
          color: Color.fromARGB(255, 246, 246, 248),
          child: Column(
            children: <Widget>[
              Container(
                height: MediaQuery.of(context).padding.top ,
              ) ,
              Container(
                height: 45,
                child: Row(
                  children: <Widget>[
                    Container(
                      width: 17,
                      height: 17,
                      margin: EdgeInsets.only(left:ScreenUtil().setWidth(19)),
                      child: GestureDetector(
                        child: Container(
                          width: 17,
                          height: 17,
                          child: Image.asset("assets/images/back.png" , fit: BoxFit.fill,),
                        ),
                        onTap: (){
                          Navigator.of(context).pop() ;
                        },
                      ),
                    ) ,
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Text("意见反馈" , style: TextStyle(
                            color: Color.fromARGB(255, 19 , 28 , 53) ,
                            fontSize: ScreenUtil().setSp(18) ,
                            fontWeight: FontWeight.bold 
                          ),),
                        ),
                      ),
                    ) ,
                    Container(
                      height: 17,
                      width: 36,
                    )
                  ],
                ),
              )  ,
              Container(
                margin: EdgeInsets.only(left:ScreenUtil().setWidth(15) , right:ScreenUtil().setWidth(15) , top:ScreenUtil().setHeight(6)),
                // height: 300 ,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(8)) ,
                  color: Colors.white
                ),
                child: Container(
                  margin: EdgeInsets.only(left:ScreenUtil().setWidth(16) , right:ScreenUtil().setWidth(16), bottom:ScreenUtil().setHeight(16)) ,
                  child: TextField(
                    decoration: InputDecoration(
                      hintText: "请填写您对我们的意见或者建议" ,
                      border: InputBorder.none ,
                      hintStyle: TextStyle(
                        height: 20 / 14 ,
                        fontSize: 14
                      )
                    ),
                    maxLength: 100 ,
                    maxLines: 12 ,
                    onChanged: (value){
                      content = value ;
                    },
                  ),
                ),
              ) ,
              GestureDetector(
                child: Container(
                  height: ScreenUtil().setHeight(48),
                  margin: EdgeInsets.only(left:ScreenUtil().setWidth(15) , right:ScreenUtil().setWidth(15) , top:ScreenUtil().setHeight(24),) ,
                  decoration: BoxDecoration(
                    color: Color.fromARGB(255, 0, 195, 206) ,
                    borderRadius: BorderRadius.all(Radius.circular(8))
                  ),
                  child: Center(
                    child: Text("提交" , style: TextStyle(
                      fontSize: ScreenUtil().setSp(18) ,
                      fontWeight: FontWeight.bold ,
                      color: Colors.white
                    ),),
                  ),
                ),
                onTap: (){
                  FocusScope.of(context).requestFocus(FocusNode());
                  if(content == null){
                    Toast.show("发送内容不能为空", context) ;
                    return ;
                  }
                  if(content == uploadContent){
                    Toast.show("此内容已经发布", context) ;
                    return ;
                  }
                  UserService().opinion(content).then((value){
                    if(value["code"] == 200){
                      Toast.show("发送成功", context) ;
                      uploadContent = content ;
                    }else{
                      Toast.show("发送失败", context) ;
                    }
                  }) ;
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}